package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.query.PjCommonQueryBean;
import com.koron.css2.newProjectCenter.impl.pubUpTime.WorkDayUtils;
import com.koron.css2.newProjectCenter.mapper.PjCommonMapper;
import com.koron.css2.newProjectCenter.mapper.WorkDayMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PjCommonQuery implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjCommonQueryBean bean = JsonUtils.objectToPojo(req.getData(), PjCommonQueryBean.class);
            if (bean.getQuery().isEmpty()) {
                return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询参数不可为空", null);
            }
            PjCommonMapper mapper = factory.getMapper(PjCommonMapper.class);

            // 查询厂商以及供应商信息、材料仓库列表
            Map<String, Object> result = new HashMap<>();
            if (bean.getQuery().equals("factory")) {
                List<Map<String, String>> list = mapper.selectFactory();
                result.put("factory", list);
                List<Map<String, String>> list2 = mapper.selectSupplier();
                result.put("supplier", list2);
                List<Map<String, String>> list3 = mapper.selectMaterial();
                result.put("material", list3);
            }
            if (bean.getQuery().equals("nodeInfo")) {
                List<Map<String, String>> list = mapper.selectNode();
                result.put("nodeInfo", list);
            }
            MessageBean<Object> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", Object.class);
            messageBean.setData(result);
            return messageBean;
        } catch (Exception e) {
            logger.error("查询失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败:", null);
        }
    }
}
